const Router = require('koa-router')
const router = new Router()
const {returnMsg,queryFn} = require("../../config")

router.get('/', async ctx => {
    ctx.body = "官网"
})

/* 导航接口 */
router.get('/nav',async ctx =>{
    let sql = `select * from nav`
    let result = await queryFn (sql)
    console.log(result)
    ctx.body = returnMsg(0,"请求成功", result)
})

/* banner接口 */
router.get('/banner',async ctx =>{
    let sql = `select * from banner`
    let result = await queryFn (sql)
    console.log(result)
    ctx.body = returnMsg(0,"请求成功", result)
})

// 获取文章列表
router.get('/list',async ctx =>{
    let sql = `select id,title,author,author,date from article`
    let result = await queryFn (sql)
    console.log(result)
    ctx.body = returnMsg(0,"请求成功", result)
})

// 根据id获取文章内容
router.get('/article',async ctx =>{
    let id = ctx.request.query.id
    console.log(id)
    ctx.request
    let sql = `select * from article where id = ${id}`
    let result = await queryFn (sql)
    console.log(result)
    ctx.body = returnMsg(0,"请求成功", result[0])
})

module.exports = router;